css: Implement inherit properties
authorBenjamin Otte <otte@redhat.com>
Tue, 17 May 2011 13:01:59 +0000 (15:01 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 20:17:58 +0000 (22:17 +0200)
Huge performance hit (slows down things roughly by a factor of 3), but
necessary for CSS conformance and for implementing "inherit" and
percentages.

gtk/gtkcssprovider.c

index e93c894ef506fd6361fdc08c524ae3a32f972ec1..5d3cffa4e6c1ab2a0bf3677d87eaacb4c0464bd2 100644 (file)
@@ -1108,38 +1108,48 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
   GtkCssProvider *css_provider;
   GtkCssProviderPrivate *priv;
   GtkStyleProperties *props;
-  guint i;
+  guint i, l, length;
 
   css_provider = GTK_CSS_PROVIDER (provider);
   priv = css_provider->priv;
+  length = gtk_widget_path_length (path);
   props = gtk_style_properties_new ();
 
   css_provider_dump_symbolic_colors (css_provider, props);
 
-  for (i = 0; i < priv->selectors_info->len; i++)
+  for (l = 1; l <= length; l++)
     {
-      SelectorStyleInfo *info;
-      GHashTableIter iter;
-      gpointer key, value;
+      for (i = 0; i < priv->selectors_info->len; i++)
+        {
+          SelectorStyleInfo *info;
+          GHashTableIter iter;
+          gpointer key, value;
 
-      info = g_ptr_array_index (priv->selectors_info, i);
+          info = g_ptr_array_index (priv->selectors_info, i);
 
-      if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path)))
-        continue;
+          if (l < length && _gtk_css_selector_get_state_flags (info->selector))
+            continue;
 
-      g_hash_table_iter_init (&iter, info->style);
+          if (!_gtk_css_selector_matches (info->selector, path, l))
+            continue;
 
-      while (g_hash_table_iter_next (&iter, &key, &value))
-        {
-          GParamSpec *pspec;
+          g_hash_table_iter_init (&iter, info->style);
 
-          if (!gtk_style_properties_lookup_property (key, NULL, &pspec))
-            continue;
+          while (g_hash_table_iter_next (&iter, &key, &value))
+            {
+              GParamSpec *pspec;
 
-          _gtk_style_properties_set_property_by_pspec (props,
-                                                       pspec,
-                                                       _gtk_css_selector_get_state_flags (info->selector),
-                                                       value);
+              if (!gtk_style_properties_lookup_property (key, NULL, &pspec))
+                continue;
+
+              if (l != length && !gtk_style_param_get_inherit (pspec))
+                continue;
+
+              _gtk_style_properties_set_property_by_pspec (props,
+                                                           pspec,
+                                                           _gtk_css_selector_get_state_flags (info->selector),
+                                                           value);
+            }
         }
     }